package com.example.demo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.util.*;


class HttpBinGetObject {
    public String url;

    public String toString() {
        return "{url " + url +"}";
    }
}

@RestController
public class SimpleController {
    @Autowired
    @Qualifier("admin")
    RestTemplate restTemplate;

    @GetMapping("/")
    public String root() {
        return "[{\"url\":\"yang\"}]";
    }

    @GetMapping("/get2")
    public String s() {
        ResponseEntity<String> s = restTemplate.getForEntity("http://httpbin.org/get", String.class);
        return s.getBody();
    }

    @GetMapping("/get")
    public String get() {
        String url = "http://localhost:9000";
        ResponseEntity<List<HttpBinGetObject>> response = restTemplate.exchange(url,
                HttpMethod.GET, HttpEntity.EMPTY,
                new ParameterizedTypeReference<>() {
                }
        );
        return response.getBody().toString();
    }
}
